<?php
declare (strict_types=1);

namespace app\api\controller;

use app\BaseController;
use app\middleware\api\Auth;
use app\model\Notices;
use app\model\NoticesUsers;
use app\validate\api\CheckId;

class Notice extends BaseController
{

    protected $middleware = [Auth::class];

    /**
     * 通知列表
     * @param int $limit
     * @return \think\response\Json
     */
    public function index($limit = 10)
    {

       $data= NoticesUsers::with('notice')->where('users_id',request()->userid)->order('id','desc')->paginate(10);
        return $this->success($data);

    }

    /**
     * 已读通知
     * @return \think\response\Json
     * @throws \app\lib\exception\BaseException
     */
    public function read()
    {
        (new CheckId())->goCheck();
        return $this->success(NoticesUsers::readNotice(request()->userid, request()->param('id')));
    }

    /**
     * 删除通知
     * @return \think\response\Json
     * @throws \app\lib\exception\BaseException
     */
    public function delete()
    {
        (new CheckId())->goCheck();
        return $this->success(NoticesUsers::deleteNotice(request()->userid, request()->param('id')));
    }
}
